function isExistUser(params) { // {user}
    // 默认返回 pending状态的Promise实例
    return new Promise(function (resolve, reject) {
        ajax({
            type: "post",
            url: "../php/isExistUser.php",
            data: {
                ...params,
            },
            dataType: "json",
            success: function (result) {
                resolve(result);  // 如果请求成功, 传递请求的数据
            }
        })
    })
}

function register(params) {  // 传一个对象参数 {user, pwd, phone, email}
    return new Promise(function (resolve, reject) {
        ajax({
            type: "post",
            url: "../php/register.php",
            // data: "user=" + user,
            data: {
                // user,
                // pwd,
                // phone,
                // email,
                ...params,
            },
            dataType: "json",
            success: function (result) {
                resolve(result);
            }
        })
    })
}
function login(params) {  // {user,pwd}
    return new Promise(function (resolve, reject) {
        ajax({
            type: "post",
            url: "../php/login.php",
            // data: "user=" + user,
            data: {
                // user,
                // pwd,
                ...params,
            },
            dataType: "json",
            success: function (result) {
                resolve(result);
            }
        })
    })
}
// function register() {
//     return new Promise(function (resolve, reject) {

//     })
// }

// request("../php/searchGradeById.php", { id: 1 }, "get");
function request(url, params = {}, type = "get") {
    return new Promise(function (resolve, reject) {
        ajax({
            type: type,
            url: url,
            data: {
                ...params,
            },
            dataType: "json",
            success: function (result) {
                resolve(result);
            }
        })
    })
}

// function isExistUser(params) {  // {user:"a123123"}
//     return request("../php/isExistUser.php", params, "post");   // Promise实例(pending)
// }

// const isExistUser = function (params) {
//     return request("../php/isExistUser.php", params, "post");
// }
// const isExistUser = (params) => {
//     return request("../php/isExistUser.php", params, "post");
// }
// const isExistUser = params => {
//     return request("../php/isExistUser.php", params, "post");
// }

const isExistUser = params => request("../php/isExistUser.php", params, "post");
const register = params => request("../php/register.php", params, "post");
const login = params => request("../php/login.php", params, "post");

const searchGradeById = params => request("../php/searchGradeById.php", params);

// isExistUser({ user: "a123123" }).then(res => {

// }).catch(res => {

// })